<?php
namespace Mapi\Controller;
use Think\Controller;
class PtController extends Controller { 

   public function index(){
   		
   		if(IS_POST && I('post.devicetype')){

   			require_once(I('server.DOCUMENT_ROOT') . '/message/' . 'function.php');
   			if(I('post.devicetype')=='IOS'){
				dump(PushAPN($_POST['device'],$title=$_POST['title'],$content=$_POST['content'], json_decode($_POST['trans'],true)));
   			}else{
				dump(PushSingleDevice($_POST['device'],$title=$_POST['title'],$content=$_POST['content'],json_decode($_POST['trans'],true)));
   			}
   			echo '<button type="button" onclick="location.href=\''.U('index').'\'">重新载入表单</button>';
   		}else{
   			$this->display();
   		}
   		
   		
   }

   public function aaaa(){
   		$trans=json_encode(array('jw'=> array('pushCode'=>100,'objectId'=>341,'userId'=>18)));
   		$this->sock_get('http://localhost/Mapi/Tui/pushUid.html', array('uid'=>204,'title'=>'111dfadsfafs','content'=>'dddddddd','trans'=>$trans));
   }

function sock_get($url, $data)
{
  
  $query_str = http_build_query($data);
  
    $info = parse_url($url);
    $fp = fsockopen($info["host"], 10085, $errno, $errstr, 3);
  $head = "GET ".$info['path']."?".$query_str." HTTP/1.0\r\n";
    $head .= "Host: ".$info['host']."\r\n";
    $head .= "\r\n";
    $write = fputs($fp, $head);
    while (!feof($fp))
    {
        $line = fread($fp,4096);
          echo $line ;
    }
}
}